﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autofac;
using Common.Interface;
using EntityFrameworkExtension.Interface;
using MainProcessor;
using MainProcessor.ContextProcessor;
using MainProcessor.Interface;
using MainProcessor.Processors;
using MainProcessor.Validation;
using NUnit.Framework;

namespace Test.Main
{
    [TestFixture]
    public class IoCTests
    {
        [SetUp]
        public void Setup()
        {
            IoC.Initialize();
        }

        [Test]
        public void EntityWrapperShouldBeConfigured()
        {
            IoC.Container.Resolve<IEfContext>();
        }

        [Test]
        public void DataCacheShouldBeConfigured()
        {
            IoC.Container.Resolve<IDataCache>();
        }

        [Test]
        public void DataControllerShouldBeConfigured()
        {
            IoC.Container.Resolve<IDataController>();
        }

        [Test]
        public void RepositoryFlushShouldBeConfigured()
        {
            IoC.Container.Resolve<IRepositoryFlush>();
        }

        [Test]
        public void ReportingFilterShouldBeConfigured()
        {
            IoC.Container.Resolve<IReportingFilter>();
        }

        [Test]
        public void LatestParentMeasuresShouldBeConfigured()
        {
            IoC.Container.Resolve<ILatestParentMeasures>();
        }

        [Test]
        public void AllProcessorShouldBeConfigured()
        {
            var value = IoC.Container.Resolve<IEnumerable<IContextProcessor>>();

            Assert.AreEqual(value.Count(), 2);
        }

        [Test]
        public void ProcessorsShouldBeConfigured()
        {
            var value = IoC.Container.Resolve<IEnumerable<IContextProcessor>>();


            Assert.IsTrue(value.ToList().Exists(x => x is ReplacedInteface1Processor));
            Assert.IsTrue(value.ToList().Exists(x => x is ReplacedInteface2Processor));
            //... etc

        }

        [Test]
        public void EntityFactoryShouldBeConfigured()
        {
            var value = IoC.Container.Resolve<IEnumerable<IEntityFactory>>();

            Assert.IsTrue(value.ToList().Exists(x => (Type)x.GetType() == typeof(EntityFactory)));
        }

        [Test]
        public void AllValidationShouldBeConfigured()
        {
            var value = IoC.Container.Resolve<IEnumerable<IValidateInput>>();

            Assert.AreEqual(value.Count(), 1);
            Assert.IsTrue(value.ToList().Exists(x => (Type)x.GetType() == typeof(ChildValidation)));
          
            
        }
    }
}
